package cn.edu.jju.stepcounter2.chart.model;


import android.util.Log;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

import cn.edu.jju.stepcounter2.SCApp;
import cn.edu.jju.stepcounter2.bean.DayData;
import rx.Single;

/**
 * Created by roor on 2016/12/15
 */

public class ChartModelImpl implements ChartModel {

    @Override
    public Single<List<DayData>> getAllDayData() {
        Single<List<DayData>> single = Single.fromCallable(new Callable<List<DayData>>() {
            @Override
            public List<DayData> call() throws Exception {
                return getDataFromDB();
            }
        });

        return single;
    }

    private List<DayData> getDataFromDB() {
        DbManager.DaoConfig daoConfig = SCApp.daoConfig;
        DbManager dbManager = x.getDb(daoConfig);
        List<DayData> all =new ArrayList<>();

        try {
            all = dbManager.selector(DayData.class).findAll();
            //Log.i("chart", "getData" + all.size());
        } catch (DbException e) {
            e.printStackTrace();

        }
        return all;

    }
}